<?php

class RecommenderController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column1';
	
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
		$form = new RecommenderForm();
		
		if(Yii::app()->getRequest()->getIsAjaxRequest()) {
			echo CActiveForm::validate($form);
			Yii::app()->end(); 
		}
		
		$this->render('index', array('form'=>$form));	
	}

	/**
	 * Performs the AJAX validation.
	 * @param CModel the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='sport-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
	
	/**
	 * Performs recommendation algorithm by ranking sports according
	 * to user's details
	 */
	 public function actionSportRanking()
	 {
		 ## POR AQUI VOY
		 $user_profile = array();
		 $formData = new RecommenderForm;
		 $formData = $_POST['RecommenderForm'];
		 $sports = Yii::app()->sportRecommender->getSports($user_profile, 10);
		 $this->renderPartial("_sportRanking", array('sports'=>$sports), false, true);
	 }
}
